package com.wwc.member.controller;

import com.wwc.common.context.LoginMemberContext;
import com.wwc.common.response.CommonResponse;
import com.wwc.common.response.PageResponse;
import com.wwc.member.controller.dto.passenger.PassengerDeleteDTO;
import com.wwc.member.controller.dto.passenger.PassengerInsertAndUpdateDTO;
import com.wwc.member.controller.dto.passenger.PassengerSelectListDTO;
import com.wwc.member.controller.vo.PassengerSelectListVO;
import com.wwc.member.service.IPassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * 乘车人 Controller
 */
@RestController
@RequestMapping("/passenger")
public class PassengerController{
	@Resource
	private IPassengerService passengerService;

	/**
	 * 新增和更新乘车人
	 */
	@PostMapping("/insert-update")
	public CommonResponse<String> insertAndUpdate(@Valid @RequestBody PassengerInsertAndUpdateDTO passengerInsertAndUpdateDTO){
		String content = passengerService.insertAndUpdate(passengerInsertAndUpdateDTO);
		return new CommonResponse<>(content);
	}

	/**
	 * 删除乘车人
	 */
	@PostMapping("/delete")
	public CommonResponse<?> delete(@Valid @RequestBody PassengerDeleteDTO passengerDeleteDTO){
		passengerService.delete(passengerDeleteDTO);
		return new CommonResponse<>();
	}

	/**
	 * 查询会员分页列表
	 */
	@GetMapping("/select-list-page")
	public CommonResponse<PageResponse<PassengerSelectListVO>> selectListPage(@Valid PassengerSelectListDTO passengerSelectListDTO){
		// 获取会员id
		passengerSelectListDTO.setMemberId(LoginMemberContext.getId());
		PageResponse<PassengerSelectListVO> pageResponse = passengerService.selectListPage(passengerSelectListDTO);
		return new CommonResponse<>(pageResponse);
	}
}
